package com.wang.rabbitmq.topicmq;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

/**
 * @author: wang
 * @date: 2021/8/3 18:54
 * @description:
 */
public class MySendTopicMq {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("root");
        factory.setPassword("root");
        factory.setPort(5672);
        factory.setHost("192.168.169.123");
        factory.setVirtualHost("/");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.exchangeDeclare("topicExchange01", BuiltinExchangeType.TOPIC);

        channel.queueDeclare("topicQueue1", true, false, false, null);
        channel.queueDeclare("topicQueue2", true, false, false, null);
        channel.queueDeclare("topicQueue3", true, false, false, null);

        channel.queueBind("topicQueue1", "topicExchange01", "a");
        channel.queueBind("topicQueue2", "topicExchange01", "a.*");
        channel.queueBind("topicQueue3", "topicExchange01", "a.#");

        channel.basicPublish("topicExchange01", "a", null, "你大爷肯定是你大爷".getBytes(StandardCharsets.UTF_8));

        channel.close();
        connection.close();
    }
}
